package com.mask.example.controller;

import com.mask.encryption.service.MaskEncryptionService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/crypto")
public class EncryptionController {

    @Autowired
    private MaskEncryptionService encryptionService;

    @PostMapping("/encrypt")
    public CipherText encrypt(@RequestBody PlainText req) {
        CipherText res = new CipherText();
        res.setCiphertext(encryptionService.encryptToBase64(req.getPlaintext()));
        return res;
    }

    @PostMapping("/decrypt")
    public PlainText decrypt(@RequestBody CipherText req) {
        PlainText res = new PlainText();
        res.setPlaintext(encryptionService.decryptFromBase64(req.getCiphertext()));
        return res;
    }

    // HYBRID 模式无需额外接口，复用同样的 encrypt/decrypt 即可

    @Data
    public static class PlainText {
        private String plaintext;
    }

    @Data
    public static class CipherText {
        private String ciphertext;
    }
}


